package lol.oxguy3.droidpong;

import android.content.Context;

public class PongPaddle extends PongEntity {
	
	boolean isLeft;
	int width, height;
	int playerScore;

	public PongPaddle(Context c, PongView v, int px, int py, int vx, int vy, int col, boolean isl) {
		this(c, v, px, py, vx, vy, col, isl, 100);
	}

	public PongPaddle(Context c, PongView v, int px, int py, int vx, int vy, int col, boolean isl, int h) {
		super(c, v, px, py, vx, vy, col);
		
		isLeft = isl;
		width = 10;
		height = h;
		
		playerScore = 0;
	}
	
	@Override
	public void onMove() {
		super.onMove();
		
		if (!isLeft) {
			int ballY = ((PongView)view).ball.getPosY();
			int centerPosY = posY+height/2;
			
			if (ballY > centerPosY) {
				if (ballY-centerPosY >= velY) {
					posY+=velY;
				}
			} else if (ballY < centerPosY) {
				if (centerPosY-ballY >= velY) {
					posY-=velY;
				}
			}
		}
	}
	
	public void greatSuccess() {
		playerScore++;
		view.ball.setPosX(view.getWidth()/2);
		view.ball.setPosY(view.getHeight()/2);
		view.paddleLeft.setPosY(view.getHeight()/2 - view.paddleLeft.getHeight()/2);
		view.paddleRight.setPosY(view.getHeight()/2 - view.paddleRight.getHeight()/2);
		view.pauseGame();
		
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
	
	public int getPlayerScore() {
		return playerScore;
	}
	
	public void setWidth(int w) {
		width = w;
	}
	
	public void setHeight(int h) {
		height = h;
	}
	
	public void setPlayerScore(int ps) {
		playerScore = ps;
	}
}
